<template>
  <div>
    为 <b> {{cinemaRoom.cinema_name}} </b>  的 <b>{{cinemaRoom.cinema_room_name}} </b> 号厅添加排片计划
    <el-divider></el-divider>
    <el-form :model="form" :rules="rules" ref="form" label-width="200px">
      <el-form-item label="选择电影"  prop="movie_id">
        <el-select v-model="form.movie_id" placeholder="请输入关键词" 
        filterable  remote reserve-keyword   :remote-method="queryMovie" >
          <el-option v-for="item in movieList" :key="item.id"
           :label="item.title" :value="item.id"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="放映日期" required>
        <el-col :span="11">
          <el-form-item prop="showingon_date">
            <el-date-picker value-format="yyyy-MM-dd"
              type="date"
              placeholder="选择日期"
              v-model="form.showingon_date"
              style="width: 50%"
            ></el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="11">
          <el-form-item prop="showingon_time">
            <el-time-picker placeholder="选择时间"
              v-model="form.showingon_time"
              :picker-options="{start:'06:00', step:'00:15',end:'24:00'}"
            ></el-time-picker>
          </el-form-item>
        </el-col>
      </el-form-item>
      <el-form-item label="票价" prop="price">
        <el-input v-model="form.price"></el-input>
      </el-form-item>
      <el-form-item label="立即发布" prop="status">
        <el-switch v-model="form.status" active-value="1" inactive-value="0"
        ></el-switch>
      </el-form-item>
      <el-form-item>
          <el-button type="primary" @click="submit()">立即新增该计划</el-button>
        <el-button >取消</el-button>
        
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
  data() {
    return {
      form: {
        cinema_id: "",
        cinema_room_id: this.$route.params.room_id,
        movie_id: "",
        showingon_date: "",
        showingon_time:'',
        status: 0, //排片计划的状态 : 0 -> 未发布
        price: 0,
      },
      rules: {
         cinema_id:[{required:true,trigger:'blur',message:'必填'}] ,
        cinema_room_id:[{required:true,trigger:'blur',message:'必填'}],
        movie_id: [{required:true,trigger:'blur',message:'必填'}],
        showingon_date: [{required:true,trigger:'blur',message:'必填'}],
        showingon_time:[{required:true,trigger:'blur',message:'必填'}],
        price: [{required:true,trigger:'blur',message:'必填'}],
      },
      cinemaRoom:{} , //当前放映厅对象信息
      movieList:[] ,  //请求到的可选的电影列表
    };
  },
  mounted(){
    // 加载放映厅的信息 : 哪个影院 哪个厅
    let params={id:this.form.cinema_room_id}
    this.$http.cinemaRoomApi.queryById(params).then(res=>{
        console.log('放映厅的信息',res);
        this.cinemaRoom=res.data.data
        this.form.cinema_id=res.data.data.cinema_id
    })
  },
  methods: {
    submit() {
        this.$refs.form.validate((valid=>{
            if(valid){
                console.log('表单信息',this.form);
                this.$http.showingonPlanApi.add(this.form).then(res=>{
                    console.log('新增计划',res);
                    if(res.data.code==200){
                        this.$message({type:'success',message:'新增计划成功'})
                        // this.$router.push(`/home/showingonplan-list/${id}`)
                    }
                })
            }
        }))
    },
    queryMovie(word){
        // 会自动将输入的文字传入参数
        // console.log(word);
        let params={name:word,page:1,pagesize:100}
        this.$http.movieApi.queryByNameLike(params).then(res=>{
            console.log('模糊查询结果',res);
            this.movieList=res.data.data.result
        })
    }
  },
};
</script>

<style lang="scss" scoped></style>
